//
//  ASGuideViewController.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/27.
//

#import "ASGuideViewController.h"
#import "ASPopupView.h"
#import "AppDelegate.h"


@interface ASGuideViewController ()

@property (strong, nonatomic) UIImageView *mainImage;
@property (strong, nonatomic) UIImageView *bottomImage;
@property (strong, nonatomic) NSTimer *timer;
@property (assign, nonatomic) NSInteger timeIndex;

@end

@implementation ASGuideViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BACKGROUND_COLOR;
    [self.view addSubview:self.bottomImage];
    [self.view addSubview:self.mainImage];
//    [self crateTimer];
    
    @weakify(self);
    [self.mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(self.bottomImage.mas_top);
    }];
    [self.bottomImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(SCREENH_HEIGHT * 0.19);
    }];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cureBtnClick) name:@"ClickPopoutViewSureBtn" object:nil];
    [self showPopupView];
    // Do any additional setup after loading the view.
}

- (void)crateTimer{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerStart) userInfo:nil repeats:YES];
    //加入runloop循环池
    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
    //开启定时器
    [self.timer fire];
}

-(void)timerStart{
    [self createHome];
 //   销毁定时器
    [_timer invalidate];
    _timer = nil;
}

- (void)showPopupView{
//    NSNumber *num = [[NSUserDefaults standardUserDefaults]objectForKey:@"AGREEPROTOCOL"];
//    if (num.boolValue == NO) {
//        [ASPopUpView showInViewWithSuperView:self];
    [ASPopupView showInViewWithSuperView:self];
//    }
}

///获取当前网络状态
-(void)loadNetState{
    // 1.获得网络监控的管理者
    AFNetworkReachabilityManager *manager =  [AFNetworkReachabilityManager sharedManager];
    // 2.设置网络状态改变后的处理
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
    // 当网络状态改变了, 就会调用这个block
    switch (status) {
        case AFNetworkReachabilityStatusUnknown: // 未知网络
            break;
        case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
            break;
        case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
            [self showPopupView];
            [self timerStart];
            break;
        case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
            [self showPopupView];
            [self timerStart];
            break;
        }
    }];
    // 3.开始监控
    [manager startMonitoring];
}

- (UIImageView *)mainImage{
    if (!_mainImage) {
        _mainImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"startup_above"]];
        _mainImage.contentMode = UIViewContentModeScaleAspectFill;
        _mainImage.clipsToBounds = YES;
    }
    return _mainImage;
}

- (UIImageView *)bottomImage{
    if (!_bottomImage) {
        _bottomImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"startup_bottom"]];
        _bottomImage.contentMode = UIViewContentModeScaleAspectFill;
        _bottomImage.clipsToBounds = YES;
    }
    return _bottomImage;
}

- (void)cureBtnClick{
    [self createHome];
}

- (void)createHome{
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [app.window setRootViewController:app.tabBar];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
